﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IUAP.DAL.Intranet;
using IUAP.DAL;

/// <summary>
/// Descripción breve de Alumno
/// </summary>
namespace IUAP.BLL.Intranet
{
    public class Alumno:BaseIntranet
    {
        public Alumno()
        {

        }

        public Alumno(string _id_alumno
            , string _nomb_alumno)
        {
            this.Id_alumno = _id_alumno;
            this.Nomb_alumno = _nomb_alumno;
        }

        string id_alumno = "";

        public string Id_alumno
        {
            get { return id_alumno; }
            set { id_alumno = value; }
        }

        string nomb_alumno = "";

        public string Nomb_alumno
        {
            get { return nomb_alumno; }
            set { nomb_alumno = value; }
        }
        public static Alumno GetAlumnos(int id_escuela, string id_alumno)
        {
            Alumno alumno = null;
            string key = "Intranet_Alumno_" + id_alumno;

            if (BaseIntranet.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                alumno = (Alumno)BizObject.Cache[key];
            }
            else
            {
                alumno = GetAlumnoFromAlumnoDetalles(SiteProvider.Intranet.GetAlumnos(id_escuela, id_alumno));
                BaseIntranet.CacheData(key, alumno);
            }
            return alumno;
        }
        public static List<Alumno> GetAlumnosbyApellido(int id_escuela, string apepaterno)
        {
            List<Alumno> alumno = null;
            string key = "Intranet_Alumnos";

            if (BaseIntranet.Settings.EnableCaching && BizObject.Cache[key] != null)
            {
                alumno = (List<Alumno>)BizObject.Cache[key];
            }
            else
            {
                List<AlumnoDetalles> recordset = SiteProvider.Intranet.GetAlumnosbyApellido(id_escuela,apepaterno);
                alumno = GetAlumnoListFromAlumnoDetallesList(recordset);
                BaseIntranet.CacheData(key, alumno);
            }
            return alumno;
        }
        private static List<Alumno> GetAlumnoListFromAlumnoDetallesList(List<AlumnoDetalles> recordset)
        {
            List<Alumno> alumno = new List<Alumno>();
            foreach (AlumnoDetalles record in recordset)
            {
                alumno.Add(GetAlumnoFromAlumnoDetalles(record));
            }
            return alumno;
        }
        private static Alumno GetAlumnoFromAlumnoDetalles(AlumnoDetalles record)
        {
            if (record == null)
                return null;
            else
            {
                return new Alumno(record.Id_alumno, record.Nomb_alumno);
            }
        }
    }
}